<template>
  <div class="content">
    <userhead></userhead>
    <div class="head">
      <div class="left">
        <input v-model="keywords" @keyup.enter="search()" placeholder="请输入搜索内容..." type="text">
        <div class="sousuo" @click="search()">
          <img src="../assets/img/sou.png" alt="">
          搜索
        </div>
      </div>
    </div>


    <el-table :data="tableData" border stripe style="width: 100%;margin-top:20px;">

      <el-table-column type="selection" fixed width="55">
      </el-table-column>
      <el-table-column type="index" fixed width="50">
      </el-table-column>
      <el-table-column prop="real_name" label="姓名" width="180">
      </el-table-column>
      <el-table-column prop="wx_account" label="微信号" width="180">
      </el-table-column>
      <el-table-column prop="mobile" label="电话" width="180">
      </el-table-column>
      <el-table-column prop="company" label="所属单位" width="180">
      </el-table-column>
      <el-table-column prop="depar" label="所属部门" width="180">
      </el-table-column>
      <el-table-column prop="time_action" label="有权限的锁列表" width="180">
      </el-table-column>
      <el-table-column prop="pd_changes" label="权限有效期" width="180">
      </el-table-column>
      <el-table-column label="状态" width="180">
        <template slot-scope="scope">
          <p v-if="scope.row.status==1">通过</p>
          <p v-if="scope.row.status==2">拒绝</p>
        </template>
      </el-table-column>

      <el-table-column width="180" label="操作">
        <template slot-scope="scope">
          <el-button size="mini" @click='edit(scope.row)'>编辑</el-button>
          <el-button size="mini" type="danger" @click='deleteuser(scope.row)'>删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination :count='count'></pagination>

    <el-dialog title="编辑" :visible.sync="dialogVisible" width="30%">
      <el-form v-model="form" label-width="100px" class="demo-ruleForm">
        <el-form-item label="姓名" prop="real_name">
          <el-input v-model="form.real_name"></el-input>
        </el-form-item>
        <el-form-item label="手机号码" prop="real_name">
          <el-input v-model="form.mobile"></el-input>
        </el-form-item>
        <el-form-item label="微信号" prop="real_name">
          <el-input v-model="form.wx_account"></el-input>
        </el-form-item>
        <el-form-item label="公司名称" prop="real_name">
          <el-input v-model="form.company"></el-input>
        </el-form-item>
        <el-form-item label="部门" prop="real_name">
          <el-input v-model="form.depar"></el-input>
        </el-form-item>
      </el-form>
      <div class="btn">
        <span @click="submit">提交</span>
        <span @click='cancle'>取消</span>
      </div>
    </el-dialog>





  </div>
</template>

<script>
  import {
    user_list,
    edit_user,
    delete_user
  } from '../js/getApi.js'
  import userhead from '../components/userhead.vue'
  import pagination from '../components/pagination'
  export default {
    components: {
      userhead,
      pagination
    },
    data() {
      return {
        count:0,
        dialogVisible: false,
        tableData: [],
        keywords:'',
        form: {
          id: '',
          real_name: '',
          mobile: '',
          company: '',
          depar: '',
          wx_account: ''
        }
      }
    },
    methods: {
      async search(){
       const data = await user_list(this.$store.state.token,this.keywords, 1, 8);
       this.tableData = data.list;
       },
      edit(row) {
        this.dialogVisible = true;

        this.form = {
          real_name: row.real_name,
          mobile: row.mobile,
          company: row.company,
          depar: row.depar,
          wx_account: row.wx_account
        }
        this.form.id = row.id;
      },
      async deleteuser(row) {

        const data = await delete_user(this.$store.state.token, row.id);
        alert(data.msg);
        if (data.code == 1) {
          this.getlist(1,1000);
        }
      },
      cancle() {
        this.dialogVisible = false;
      },
      async getlist(page,size) {
        const data = await user_list(this.$store.state.token, '', page, size);
        this.tableData = data.list;
        this.count=data.count;
      },
      async submit() {
        const data = await edit_user(this.$store.state.token, this.form);
        alert(data.msg);
        if (data.code == 1) {
          this.getlist(1,1000);
          this.dialogVisible = false;
        }
      }
    },
    created() {
      this.getlist(1,8);
    }
  }
</script>

<style scoped>
  .head {
    margin-top: 33px;
    display: flex;
  }

  .head div {
    display: inline-block;
  }

  .head input {
    width: 190px;
    height: 30px;
    border-radius: 10px 0 0 10px;
    padding-left: 10px;
    border: 1px solid rgba(187, 187, 187, 100);
    float: left;
  }

  .sousuo {
    width: 88px;
    height: 34px;
    line-height: 34px;
    background-color: rgba(26, 188, 156, 100);
    text-align: center;
    border: 1px solid rgba(255, 255, 255, 100);
    float: left;
    margin-left: -1px;
    margin-top: -1px;
    color: #fff;
    cursor: pointer;
  }

  .sousuo img {
    width: 19px;
    height: 19px;
    vertical-align: middle;
  }

  .btn {
    margin-left: 100px;
    margin-top: 100px;
  }

  .btn span {
    display: inline-block;
    cursor: pointer;
  }

  .btn span:nth-of-type(1) {
    width: 100px;
    height: 34px;
    line-height: 34px;
    border-radius: 2px;
    background-color: rgba(26, 188, 156, 100);
    color: rgba(255, 255, 255, 100);
    font-size: 14px;
    text-align: center;
    font-family: Roboto;
  }

  .btn span:nth-of-type(2) {
    width: 100px;
    height: 34px;
    line-height: 34px;
    border-radius: 2px;
    background-color: rgba(255, 255, 255, 100);
    color: rgba(26, 188, 156, 100);
    font-size: 14px;
    text-align: center;
    font-family: Roboto;
    border: 1px solid rgba(26, 188, 156, 100);
    margin-left: 20px;
  }
</style>
